<template>
  <view class="cardlist">
      <scroll-view scroll-y="true" class="box">
        <block v-for="item in cardInfo" :key="item.id">
            <navigator :url="'./using?id='+item.id" class="item" 
            :class="{overdue:new Date().getTime()> new Date(item.expire_at).getTime()|| item.is_use==1}"  
            v-if="item.is_use!=5" >
            <view class="left" :style="'background-image:url('+item.images||'http://activity.yqnq.net/img/coup.29177801.png'+')'">
            </view>
            <view class="right">
                <view class="title">
                <text class="brand">必胜客</text>
                <text class="use" >
                    {{new Date().getTime()> new Date(item.expire_at).getTime() ? '已过期' : 
                    item.is_use==0 ? '未使用' : '已使用'}}
                    </text>
                </view>
                <view class="name">{{item.title}}</view>
                <view class="time">{{item.expire_at}}</view>
            </view>
            </navigator>
        </block> 
      </scroll-view> 
  </view>
</template>

<script>
import { Button, Dialog, Toast } from "vant";
import { checkCard } from '../../api/content'
export default {
    data () {
        return {
            userParam:uni.getStorageSync('user'),
            cardInfo:[]
        }
    },
    onLoad(){
        // console.log(this.userParam);
        this.getCardInfo()
    },
    methods: {
     async getCardInfo(){
        this.cardInfo = await checkCard({
            activity_id:this.userParam.id,
            user_id:this.userParam.user_id
            })
        console.log(this.cardInfo);
      }
    },
}
</script>

<style lang="scss" scoped>
.box {
    .item {
        position: relative;
        display: flex;
        width: 343 / 375 * 100vw;
        height: 112 / 375 * 100vw;
        margin: 0 auto;
        margin-top: 16 / 375 * 100vw;
        background-color: #fff;
        border-radius: 10 / 375 * 100vw;
        overflow: hidden;
        .left {
            width: 94 / 375 * 100vw;
            background-color: #f6f6f6;
            display: flex;
            justify-content: center;
            align-items: center;
            background: no-repeat center ;
            background-size: cover;
        }
        // 优惠券右边
        .right {
            margin-left: 15 / 375 * 100vw;
            padding: 22 / 375 * 100vw 0 23 / 375 * 100vw 0;
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            text-align: left;
            .title {
                font-size: 16 / 375 * 100vw;
                font-weight: bold;
                color: #333333;
                line-height: 20 / 375 * 100vw;
                display: flex;
                align-items: center;
                margin-bottom: 7 / 375 * 100vw;
                .brand {
                    font-size: 16 / 375 * 100vw;
                    font-weight: bold;
                    color: #333333;
                    margin-right: 6 / 375 * 100vw;
                }
                .use {
                padding: 2 / 375 * 100vw 4 / 375 * 100vw;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 9 / 375 * 100vw;
                line-height: 13 / 375 * 100vw;
                font-weight: bold;
                color: #FFFFFF;
                text-align: center;
                background-image: linear-gradient(to right, $bg-color-l,$bg-color-r);
                border-radius: 100 / 375 * 100vw;
            }
            }
            .name {
                font-size: 12 / 375 * 100vw;
                font-weight: 500;
                color: #666666;
                margin-bottom: 4 / 375 * 100vw;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }
            .time {
                font-size: 12 / 375 * 100vw;
                font-weight: 500;
                color: #6F20E8;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }
        }
        // 黑点模拟
    &::before {
        content: '';
        position: absolute;
        width: 22 / 375 * 100vw;
        height: 22 / 375 * 100vw;
        background-color: #12151A;
        border-radius: 100 / 375 * 100vw;
        left: -11 / 375 * 100vw;
        top: 0;
        bottom: 0;
        margin: auto;
    }
    &::after {
        content: '';
        position: absolute;
        width: 22 / 375 * 100vw;
        height: 22 / 375 * 100vw;
        background-color: #12151A;
        border-radius: 100 / 375 * 100vw;
        right: -11 / 375 * 100vw;
        top: 0;
        bottom: 0;
        margin: auto;
    }
    }
    // 过期样式和已使用
    .overdue{
        .right{
            .title{
                .use{
                    background-image: linear-gradient(to right, #ccc , #ccc);
                }
            }
            .time{
                color: #666666;
            }
        }
    }
}
</style>